/*
 * RangeTest.cpp
 *
 *  Created on: 06-12-2010
 *      Author: Przemek
 */

#include "utils/Range.hpp"
#include "utils/MathUtils.hpp"

#define BOOST_TEST_MODULE Range test
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( assignmentOperatorTest )
{
	const Range<int> firstRange(100, 10);

	const Range<int> secondRange = firstRange;
	BOOST_CHECK_EQUAL(firstRange.getMinimum(), secondRange.getMinimum());
	BOOST_CHECK_EQUAL(firstRange.getMaximum(), secondRange.getMaximum());
}

BOOST_AUTO_TEST_CASE( minimumSmallerThanMaximumTest )
{
	const Range<int> range(100, 10);

	BOOST_CHECK_EQUAL(range.getMinimum(), 10);
	BOOST_CHECK_EQUAL(range.getMaximum(), 100);
}

BOOST_AUTO_TEST_CASE( isBeforeMinimumTest )
{
	const Range<int> range(10, 100);

	BOOST_CHECK_EQUAL(range.isBeforeMinimum(5), true);
	BOOST_CHECK_EQUAL(range.isBeforeMinimum(10), false);
	BOOST_CHECK_EQUAL(range.isBeforeMinimum(20), false);
	BOOST_CHECK_EQUAL(range.isBeforeMinimum(100), false);
	BOOST_CHECK_EQUAL(range.isBeforeMinimum(120), false);
}

BOOST_AUTO_TEST_CASE( isAfterMaximumTest )
{
	const Range<int> range(10, 100);

	BOOST_CHECK_EQUAL(range.isAfterMaximum(5), false);
	BOOST_CHECK_EQUAL(range.isAfterMaximum(10), false);
	BOOST_CHECK_EQUAL(range.isAfterMaximum(20), false);
	BOOST_CHECK_EQUAL(range.isAfterMaximum(100), false);
	BOOST_CHECK_EQUAL(range.isAfterMaximum(120), true);
}

BOOST_AUTO_TEST_CASE( averageTest )
{
	BOOST_CHECK_EQUAL(Range<int>(10,100).getAverage(), 55);
	BOOST_CHECK_EQUAL(Range<int>(-10,10).getAverage(), 0);
	BOOST_CHECK_EQUAL(Range<int>(-50,-60).getAverage(), -55);

	BOOST_CHECK_EQUAL(MathUtils::isEqual(Range<float>(10.0f,100.0f).getAverage(), 55.0f),true);
	BOOST_CHECK_EQUAL(MathUtils::isEqual(Range<float>(-10.0f,10.0f).getAverage(), 0.0f),true);
	BOOST_CHECK_EQUAL(MathUtils::isEqual(Range<float>(-50.0f,-60.0f).getAverage(), -55.0f),true);
}

BOOST_AUTO_TEST_CASE( extentTest )
{
	BOOST_CHECK_EQUAL(Range<int>(10,100).getExtent(), 90);
	BOOST_CHECK_EQUAL(Range<int>(-10,10).getExtent(), 20);
	BOOST_CHECK_EQUAL(Range<int>(-50,-60).getExtent(), 10);

	BOOST_CHECK_EQUAL(MathUtils::isEqual(Range<float>(10.0f,100.0f).getExtent(), 90.0f),true);
	BOOST_CHECK_EQUAL(MathUtils::isEqual(Range<float>(-10.0f,10.0f).getExtent(), 20.0f),true);
	BOOST_CHECK_EQUAL(MathUtils::isEqual(Range<float>(-50.0f,-60.0f).getExtent(), 10.0f),true);
}

